home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / dix / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-14  |  18.2 KB  |  624 lines

  1. /***********************************************************
  2. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24. /* $XConsortium: main.c,v 5.9 89/10/03 19:57:00 rws Exp $ */
  25.  
  26. #include "X.h"
  27. #include "Xproto.h"
  28. #include "input.h"
  29. #include "scrnintstr.h"
  30. #include "misc.h"
  31. #include "os.h"
  32. #include "windowstr.h"
  33. #include "resource.h"
  34. #include "dixstruct.h"
  35. #include "gcstruct.h"
  36. #include "extension.h"
  37. #include "colormap.h"
  38. #include "cursorstr.h"
  39. #include "opaque.h"
  40. #include "servermd.h"
  41.  
  42. extern long defaultScreenSaverTime;
  43. extern long defaultScreenSaverInterval;
  44. extern int defaultScreenSaverBlanking;
  45. extern int defaultScreenSaverAllowExposures;
  46.  
  47. void ddxGiveUp();
  48.  
  49. extern char *display;
  50. char *ConnectionInfo;
  51. xConnSetupPrefix connSetupPrefix;
  52.  
  53. extern WindowPtr *WindowTable;
  54. extern FontPtr defaultFont;
  55.  
  56. extern void SetInputCheck();
  57. extern void InitProcVectors();
  58. extern void InitEvents();
  59. extern void InitExtensions();
  60. extern void DefineInitialRootWindow();
  61. extern void QueryMinMaxKeyCodes();
  62. extern Bool InitClientResources();
  63. static Bool CreateConnectionBlock();
  64. extern Bool CreateGCperDepthArray();
  65. extern Bool CreateDefaultStipple();
  66. extern void ResetWellKnownSockets();
  67. extern void ResetWindowPrivates();
  68. extern void ResetGCPrivates();
  69. static void FreeScreen();
  70. static void ResetScreenPrivates();
  71.  
  72. PaddingInfo PixmapWidthPaddingInfo[33];
  73. int connBlockScreenStart;
  74.  
  75. static int restart = 0;
  76.  
  77. void
  78. NotImplemented()
  79. {
  80.     FatalError("Not implemented");
  81. }
  82.  
  83. /*
  84.  * This array encodes the answer to the question "what is the log base 2
  85.  * of the number of pixels that fit in a scanline pad unit?"
  86.  * Note that ~0 is an invalid entry (mostly for the benefit of the reader).
  87.  */
  88. static int answer[6][3] = {
  89.     /* pad   pad   pad */
  90.     /*  8     16    32 */
  91.  
  92.     {   3,     4,    5 },    /* 1 bit per pixel */
  93.     {   1,     2,    3 },    /* 4 bits per pixel */
  94.     {   0,     1,    2 },    /* 8 bits per pixel */
  95.     {   ~0,    0,    1 },    /* 16 bits per pixel */
  96.     {   ~0,    ~0,   0 },    /* 24 bits per pixel */
  97.     {   ~0,    ~0,   0 }    /* 32 bits per pixel */
  98. };
  99.  
  100. /*
  101.  * This array gives the answer to the question "what is the first index for
  102.  * the answer array above given the number of bits per pixel?"
  103.  * Note that ~0 is an invalid entry (mostly for the benefit of the reader).
  104.  */
  105. static int indexForBitsPerPixel[ 33 ] = {
  106.     ~0, 0, ~0, ~0,    /* 1 bit per pixel */
  107.     1, ~0, ~0, ~0,    /* 4 bits per pixel */
  108.     2, ~0, ~0, ~0,    /* 8 bits per pixel */
  109.     ~0,~0, ~0, ~0,
  110.     3, ~0, ~0, ~0,    /* 16 bits per pixel */
  111.     ~0,~0, ~0, ~0,
  112.     4, ~0, ~0, ~0,    /* 24 bits per pixel */
  113.     ~0,~0, ~0, ~0,
  114.     5        /* 32 bits per pixel */
  115. };
  116.  
  117. /*
  118.  * This array gives the answer to the question "what is the second index for
  119.  * the answer array above given the number of bits per scanline pad unit?"
  120.  * Note that ~0 is an invalid entry (mostly for the benefit of the reader).
  121.  */
  122. static int indexForScanlinePad[ 33 ] = {
  123.     ~0, ~0, ~0, ~0,
  124.     ~0, ~0, ~0, ~0,
  125.     0,  ~0, ~0, ~0,    /* 8 bits per scanline pad unit */
  126.     ~0, ~0, ~0, ~0,
  127.     1,  ~0, ~0, ~0,    /* 16 bits per scanline pad unit */
  128.     ~0, ~0, ~0, ~0,
  129.     ~0, ~0, ~0, ~0,
  130.     ~0, ~0, ~0, ~0,
  131.     2        /* 32 bits per scanline pad unit */
  132. };
  133.  
  134. main(argc, argv)
  135.     int        argc;
  136.     char    *argv[];
  137. {
  138.     int        i, j, k;
  139.     long    alwaysCheckForInput[2];
  140.  
  141.     /* Notice if we're restart.  Probably this is because we jumped through
  142.      * uninitialized pointer */
  143.     if (restart)
  144.     FatalError("server restarted. Jumped through uninitialized pointer?\n");
  145.     else
  146.     restart = 1;
  147.     /* These are needed by some routines which are called from interrupt
  148.      * handlers, thus have no direct calling path back to main and thus
  149.      * can't be passed argc, argv as parameters */
  150.     argcGlobal = argc;
  151.     argvGlobal = argv;
  152.     display = "0";
  153.     ProcessCommandLine(argc, argv);
  154.  
  155.     alwaysCheckForInput[0] = 0;
  156.     alwaysCheckForInput[1] = 1;
  157.     while(1)
  158.     {
  159.     serverGeneration++;
  160.         ScreenSaverTime = defaultScreenSaverTime;
  161.     ScreenSaverInterval = defaultScreenSaverInterval;
  162.     ScreenSaverBlanking = defaultScreenSaverBlanking;
  163.     ScreenSaverAllowExposures = defaultScreenSaverAllowExposures;
  164.     InitBlockAndWakeupHandlers();
  165.     /* Perform any operating system dependent initializations you'd like */
  166.     OsInit();        
  167.     if(serverGeneration == 1)
  168.     {
  169.         CreateWellKnownSockets();
  170.         InitProcVectors();
  171.         clients = (ClientPtr *)xalloc(MAXCLIENTS * sizeof(ClientPtr));
  172.         if (!clients)
  173.         FatalError("couldn't create client array");
  174.         for (i=1; i<MAXCLIENTS; i++) 
  175.         clients[i] = NullClient;
  176.         serverClient = (ClientPtr)xalloc(sizeof(ClientRec));
  177.         if (!serverClient)
  178.         FatalError("couldn't create server client");
  179.             serverClient->sequence = 0;
  180.             serverClient->closeDownMode = RetainPermanent;
  181.             serverClient->clientGone = FALSE;
  182.             serverClient->lastDrawable = (DrawablePtr)NULL;
  183.         serverClient->lastDrawableID = INVALID;
  184.             serverClient->lastGC = (GCPtr)NULL;
  185.         serverClient->lastGCID = INVALID;
  186.         serverClient->numSaved = 0;
  187.         serverClient->saveSet = (pointer *)NULL;
  188.         serverClient->index = 0;
  189.         serverClient->clientAsMask = (Mask)0;
  190.     }
  191.     else
  192.         ResetWellKnownSockets ();
  193.         clients[0] = serverClient;
  194.         currentMaxClients = 1;
  195.  
  196.     if (!InitClientResources(serverClient))      /* for root resources */
  197.         FatalError("couldn't init server resources");
  198.  
  199.     SetInputCheck(&alwaysCheckForInput[0], &alwaysCheckForInput[1]);
  200.     screenInfo.arraySize = MAXSCREENS;
  201.     screenInfo.numScreens = 0;
  202.     WindowTable = (WindowPtr *)xalloc(MAXSCREENS * sizeof(WindowPtr));
  203.     if (!WindowTable)
  204.         FatalError("couldn't create root window table");
  205.  
  206.     /*
  207.      * Just in case the ddx doesnt supply a format for depth 1 (like qvss).
  208.      */
  209.     j = indexForBitsPerPixel[ 1 ];
  210.     k = indexForScanlinePad[ BITMAP_SCANLINE_PAD ];
  211.     PixmapWidthPaddingInfo[1].padRoundUp = BITMAP_SCANLINE_PAD-1;
  212.     PixmapWidthPaddingInfo[1].padPixelsLog2 = answer[j][k];
  213.      j = indexForBitsPerPixel[8]; /* bits per byte */
  214.      PixmapWidthPaddingInfo[1].padBytesLog2 = answer[j][k];
  215.  
  216.     InitAtoms();
  217.     InitEvents();
  218.     ResetScreenPrivates();
  219.     ResetWindowPrivates();
  220.     ResetGCPrivates();
  221.     InitOutput(&screenInfo, argc, argv);
  222.     if (screenInfo.numScreens < 1)
  223.         FatalError("no screens found");
  224.     InitExtensions(argc, argv);
  225.     for (i = 0; i < screenInfo.numScreens; i++)
  226.     {
  227.         if (!CreateRootWindow(screenInfo.screens[i]))
  228.         FatalError("failed to create root window");
  229.     }
  230.     InitInput(argc, argv);
  231.     if (InitAndStartDevices() != Success)
  232.         FatalError("failed to initialize core devices");
  233.  
  234.     if (SetDefaultFontPath(defaultFontPath) != Success)
  235.         ErrorF("failed to set default font path '%s'", defaultFontPath);
  236.     if (!SetDefaultFont(defaultTextFont))
  237.         FatalError("could not open default font '%s'", defaultTextFont);
  238.     if (!(rootCursor = CreateRootCursor(defaultCursorFont, 0)))
  239.         FatalError("could not open default cursor font '%s'",
  240.                defaultCursorFont);
  241.     for (i = 0; i < screenInfo.numScreens; i++)
  242.         InitRootWindow(WindowTable[i]);
  243.         DefineInitialRootWindow(WindowTable[0]);
  244.  
  245.     if (!CreateConnectionBlock())
  246.         FatalError("could not create connection block info");
  247.  
  248.     Dispatch();
  249.  
  250.     /* Now free up whatever must be freed */
  251.     CloseDownExtensions();
  252.     FreeAllResources();
  253.     CloseDownDevices();
  254.     for (i = screenInfo.numScreens - 1; i >= 0; i--)
  255.     {
  256.         FreeGCperDepth(i);
  257.         FreeDefaultStipple(i);
  258.         (* screenInfo.screens[i]->CloseScreen)(i, screenInfo.screens[i]);
  259.         FreeScreen(screenInfo.screens[i]);
  260.         screenInfo.numScreens = i;
  261.     }
  262.     xfree(WindowTable);
  263.  
  264.         CloseFont(defaultFont, (Font)0);
  265.         defaultFont = (FontPtr)NULL;
  266.  
  267.     if (dispatchException & DE_TERMINATE)
  268.     {
  269.         ddxGiveUp();
  270.         break;
  271.     }
  272.  
  273.     xfree(ConnectionInfo);
  274.     }
  275.     exit(0);
  276. }
  277.  
  278. static int padlength[4] = {0, 3, 2, 1};
  279.  
  280. static Bool
  281. CreateConnectionBlock()
  282. {
  283.     xConnSetup setup;
  284.     xWindowRoot root;
  285.     xDepth    depth;
  286.     xVisualType visual;
  287.     xPixmapFormat format;
  288.     unsigned long vid;
  289.     int i, j, k,
  290.         lenofblock,
  291.         sizesofar = 0;
  292.     char *pBuf;
  293.  
  294.     
  295.     /* Leave off the ridBase and ridMask, these must be sent with 
  296.        connection */
  297.  
  298.     setup.release = VENDOR_RELEASE;
  299.     /*
  300.      * per-server image and bitmap parameters are defined in Xmd.h
  301.      */
  302.     setup.imageByteOrder = screenInfo.imageByteOrder;
  303.     setup.bitmapScanlineUnit  = screenInfo.bitmapScanlineUnit;
  304.     setup.bitmapScanlinePad = screenInfo.bitmapScanlinePad;
  305.     setup.bitmapBitOrder = screenInfo.bitmapBitOrder;
  306.     setup.motionBufferSize = NumMotionEvents();
  307.     setup.numRoots = screenInfo.numScreens;
  308.     setup.nbytesVendor = strlen(VENDOR_STRING); 
  309.     setup.numFormats = screenInfo.numPixmapFormats;
  310.     setup.maxRequestSize = MAX_REQUEST_SIZE;
  311.     QueryMinMaxKeyCodes(&setup.minKeyCode, &setup.maxKeyCode);
  312.     
  313.     lenofblock = sizeof(xConnSetup) + 
  314.             ((setup.nbytesVendor + 3) & ~3) +
  315.         (setup.numFormats * sizeof(xPixmapFormat)) +
  316.             (setup.numRoots * sizeof(xWindowRoot));
  317.     ConnectionInfo = (char *) xalloc(lenofblock);
  318.     if (!ConnectionInfo)
  319.     return FALSE;
  320.  
  321.     bcopy((char *)&setup, ConnectionInfo, sizeof(xConnSetup));
  322.     sizesofar = sizeof(xConnSetup);
  323.     pBuf = ConnectionInfo + sizeof(xConnSetup);
  324.  
  325.     bcopy(VENDOR_STRING, pBuf, (int)setup.nbytesVendor);
  326.     sizesofar += setup.nbytesVendor;
  327.     pBuf += setup.nbytesVendor;
  328.     i = padlength[setup.nbytesVendor & 3];
  329.     sizesofar += i;
  330.     while (--i >= 0)
  331.         *pBuf++ = 0;
  332.     
  333.     for (i=0; i<screenInfo.numPixmapFormats; i++)
  334.     {
  335.     format.depth = screenInfo.formats[i].depth;
  336.     format.bitsPerPixel = screenInfo.formats[i].bitsPerPixel;
  337.     format.scanLinePad = screenInfo.formats[i].scanlinePad;
  338.     bcopy((char *)&format, pBuf, sizeof(xPixmapFormat));
  339.     pBuf += sizeof(xPixmapFormat);
  340.     sizesofar += sizeof(xPixmapFormat);
  341.     }
  342.  
  343.     connBlockScreenStart = sizesofar;
  344.     for (i=0; i<screenInfo.numScreens; i++) 
  345.     {
  346.     ScreenPtr    pScreen;
  347.     DepthPtr    pDepth;
  348.     VisualPtr    pVisual;
  349.  
  350.     pScreen = screenInfo.screens[i];
  351.     root.windowId = WindowTable[i]->drawable.id;
  352.     root.defaultColormap = pScreen->defColormap;
  353.     root.whitePixel = pScreen->whitePixel;
  354.     root.blackPixel = pScreen->blackPixel;
  355.     root.currentInputMask = 0;    /* filled in when sent */
  356.     root.pixWidth = pScreen->width;
  357.     root.pixHeight = pScreen->height;
  358.     root.mmWidth = pScreen->mmWidth;
  359.     root.mmHeight = pScreen->mmHeight;
  360.     root.minInstalledMaps = pScreen->minInstalledCmaps;
  361.     root.maxInstalledMaps = pScreen->maxInstalledCmaps; 
  362.     root.rootVisualID = pScreen->rootVisual;        
  363.     root.backingStore = pScreen->backingStoreSupport;
  364.     root.saveUnders = pScreen->saveUnderSupport != NotUseful;
  365.     root.rootDepth = pScreen->rootDepth;
  366.     root.nDepths = pScreen->numDepths;
  367.     bcopy((char *)&root, pBuf, sizeof(xWindowRoot));
  368.     sizesofar += sizeof(xWindowRoot);
  369.     pBuf += sizeof(xWindowRoot);
  370.  
  371.     pDepth = pScreen->allowedDepths;
  372.     for(j = 0; j < pScreen->numDepths; j++, pDepth++)
  373.     {
  374.         lenofblock += sizeof(xDepth) + 
  375.             (pDepth->numVids * sizeof(xVisualType));
  376.         pBuf = (char *)xrealloc(ConnectionInfo, lenofblock);
  377.         if (!pBuf)
  378.         {
  379.         xfree(ConnectionInfo);
  380.         return FALSE;
  381.         }
  382.         ConnectionInfo = pBuf;
  383.         pBuf += sizesofar;            
  384.         depth.depth = pDepth->depth;
  385.         depth.nVisuals = pDepth->numVids;
  386.         bcopy((char *)&depth, pBuf, sizeof(xDepth));
  387.         pBuf += sizeof(xDepth);
  388.         sizesofar += sizeof(xDepth);
  389.         for(k = 0; k < pDepth->numVids; k++)
  390.         {
  391.         vid = pDepth->vids[k];
  392.         for (pVisual = pScreen->visuals;
  393.              pVisual->vid != vid;
  394.              pVisual++)
  395.             ;
  396.         visual.visualID = vid;
  397.         visual.class = pVisual->class;
  398.         visual.bitsPerRGB = pVisual->bitsPerRGBValue;
  399.         visual.colormapEntries = pVisual->ColormapEntries;
  400.         visual.redMask = pVisual->redMask;
  401.         visual.greenMask = pVisual->greenMask;
  402.         visual.blueMask = pVisual->blueMask;
  403.         bcopy((char *)&visual, pBuf, sizeof(xVisualType));
  404.         pBuf += sizeof(xVisualType);
  405.         sizesofar += sizeof(xVisualType);
  406.         }
  407.     }
  408.     }
  409.     connSetupPrefix.success = xTrue;
  410.     connSetupPrefix.length = lenofblock/4;
  411.     connSetupPrefix.majorVersion = X_PROTOCOL;
  412.     connSetupPrefix.minorVersion = X_PROTOCOL_REVISION;
  413.     return TRUE;
  414. }
  415.  
  416. static int  screenPrivateCount;
  417.  
  418. static void
  419. ResetScreenPrivates()
  420. {
  421.     screenPrivateCount = 0;
  422. }
  423.  
  424. /* this can be called after some screens have been created,
  425.  * so we have to worry about resizing existing devPrivates
  426.  */
  427. int
  428. AllocateScreenPrivateIndex()
  429. {
  430.     int        index;
  431.     int        i;
  432.     ScreenPtr    pScreen;
  433.     DevUnion    *nprivs;
  434.  
  435.     index = screenPrivateCount++;
  436.     for (i = 0; i < screenInfo.numScreens; i++)
  437.     {
  438.     pScreen = screenInfo.screens[i];
  439.     nprivs = (DevUnion *)xrealloc(pScreen->devPrivates,
  440.                       screenPrivateCount * sizeof(DevUnion));
  441.     if (!nprivs)
  442.     {
  443.         screenPrivateCount--;
  444.         return -1;
  445.     }
  446.     pScreen->devPrivates = nprivs;
  447.     }
  448.     return index;
  449. }
  450.  
  451. Bool
  452. AllocateWindowPrivate(pScreen, index, amount)
  453.     register ScreenPtr pScreen;
  454.     int index;
  455.     unsigned amount;
  456. {
  457.     unsigned oldamount;
  458.  
  459.     if (index >= pScreen->WindowPrivateLen)
  460.     {
  461.     unsigned *nsizes;
  462.     nsizes = (unsigned *)xrealloc(pScreen->WindowPrivateSizes,
  463.                       (index + 1) * sizeof(unsigned));
  464.     if (!nsizes)
  465.         return FALSE;
  466.     while (pScreen->WindowPrivateLen <= index)
  467.     {
  468.         nsizes[pScreen->WindowPrivateLen++] = 0;
  469.         pScreen->totalWindowSize += sizeof(DevUnion);
  470.     }
  471.     pScreen->WindowPrivateSizes = nsizes;
  472.     }
  473.     oldamount = pScreen->WindowPrivateSizes[index];
  474.     if (amount > oldamount)
  475.     {
  476.     pScreen->WindowPrivateSizes[index] = amount;
  477.     pScreen->totalWindowSize += (amount - oldamount);
  478.     }
  479.     return TRUE;
  480. }
  481.  
  482. Bool
  483. AllocateGCPrivate(pScreen, index, amount)
  484.     register ScreenPtr pScreen;
  485.     int index;
  486.     unsigned amount;
  487. {
  488.     unsigned oldamount;
  489.  
  490.     if (index >= pScreen->GCPrivateLen)
  491.     {
  492.     unsigned *nsizes;
  493.     nsizes = (unsigned *)xrealloc(pScreen->GCPrivateSizes,
  494.                       (index + 1) * sizeof(unsigned));
  495.     if (!nsizes)
  496.         return FALSE;
  497.     while (pScreen->GCPrivateLen <= index)
  498.     {
  499.         nsizes[pScreen->GCPrivateLen++] = 0;
  500.         pScreen->totalGCSize += sizeof(DevUnion);
  501.     }
  502.     pScreen->GCPrivateSizes = nsizes;
  503.     }
  504.     oldamount = pScreen->GCPrivateSizes[index];
  505.     if (amount > oldamount)
  506.     {
  507.     pScreen->GCPrivateSizes[index] = amount;
  508.     pScreen->totalGCSize += (amount - oldamount);
  509.     }
  510.     return TRUE;
  511. }
  512.  
  513. /*
  514.     grow the array of screenRecs if necessary.
  515.     call the device-supplied initialization procedure 
  516. with its screen number, a pointer to its ScreenRec, argc, and argv.
  517.     return the number of successfully installed screens.
  518.  
  519. */
  520.  
  521. int
  522. AddScreen(pfnInit, argc, argv)
  523.     Bool    (* pfnInit)();
  524.     int argc;
  525.     char **argv;
  526. {
  527.  
  528.     int i;
  529.     int scanlinepad, format, depth, bitsPerPixel, j, k;
  530.     ScreenPtr pScreen;
  531. #ifdef DEBUG
  532.     void    (**jNI) ();
  533. #endif /* DEBUG */
  534.  
  535.     i = screenInfo.numScreens;
  536.     if (i == MAXSCREENS)
  537.     return -1;
  538.  
  539.     pScreen = (ScreenPtr) xalloc(sizeof(ScreenRec));
  540.     if (!pScreen)
  541.     return -1;
  542.  
  543.     pScreen->devPrivates = (DevUnion *)xalloc(screenPrivateCount *
  544.                           sizeof(DevUnion));
  545.     if (!pScreen->devPrivates && screenPrivateCount)
  546.     {
  547.     xfree(pScreen);
  548.     return -1;
  549.     }
  550.     pScreen->myNum = i;
  551.     pScreen->WindowPrivateLen = 0;
  552.     pScreen->WindowPrivateSizes = (unsigned *)NULL;
  553.     pScreen->totalWindowSize = sizeof(WindowRec);
  554.     pScreen->GCPrivateLen = 0;
  555.     pScreen->GCPrivateSizes = (unsigned *)NULL;
  556.     pScreen->totalGCSize = sizeof(GC);
  557.     
  558. #ifdef DEBUG
  559.     for (jNI = &pScreen->QueryBestSize; 
  560.      jNI < (void (**) ()) &pScreen->SendGraphicsExpose;
  561.      jNI++)
  562.     *jNI = NotImplemented;
  563. #endif /* DEBUG */
  564.  
  565.     /*
  566.      * This loop gets run once for every Screen that gets added,
  567.      * but thats ok.  If the ddx layer initializes the formats
  568.      * one at a time calling AddScreen() after each, then each
  569.      * iteration will make it a little more accurate.  Worst case
  570.      * we do this loop N * numPixmapFormats where N is # of screens.
  571.      * Anyway, this must be called after InitOutput and before the
  572.      * screen init routine is called.
  573.      */
  574.     for (format=0; format<screenInfo.numPixmapFormats; format++)
  575.     {
  576.      depth = screenInfo.formats[format].depth;
  577.      bitsPerPixel = screenInfo.formats[format].bitsPerPixel;
  578.       scanlinepad = screenInfo.formats[format].scanlinePad;
  579.      j = indexForBitsPerPixel[ bitsPerPixel ];
  580.       k = indexForScanlinePad[ scanlinepad ];
  581.      PixmapWidthPaddingInfo[ depth ].padPixelsLog2 = answer[j][k];
  582.      PixmapWidthPaddingInfo[ depth ].padRoundUp =
  583.          (scanlinepad/bitsPerPixel) - 1;
  584.      j = indexForBitsPerPixel[ 8 ]; /* bits per byte */
  585.      PixmapWidthPaddingInfo[ depth ].padBytesLog2 = answer[j][k];
  586.     }
  587.   
  588.     /* This is where screen specific stuff gets initialized.  Load the
  589.        screen structure, call the hardware, whatever.
  590.        This is also where the default colormap should be allocated and
  591.        also pixel values for blackPixel, whitePixel, and the cursor
  592.        Note that InitScreen is NOT allowed to modify argc, argv, or
  593.        any of the strings pointed to by argv.  They may be passed to
  594.        multiple screens. 
  595.     */ 
  596.     pScreen->rgf = ~0L;  /* there are no scratch GCs yet*/
  597.     WindowTable[i] = NullWindow;
  598.     screenInfo.screens[i] = pScreen;
  599.     screenInfo.numScreens++;
  600.     if ((*pfnInit)(i, pScreen, argc, argv))
  601.     {
  602.     if (CreateGCperDepth(i))
  603.     {
  604.         if (CreateDefaultStipple(i))
  605.         return i;
  606.         FreeGCperDepth(i);
  607.     }
  608.     FreeResource(WindowTable[i]->drawable.id, RT_NONE);
  609.     }
  610.     FreeScreen(pScreen);
  611.     screenInfo.numScreens--;
  612.     return -1;
  613. }
  614.  
  615. static void
  616. FreeScreen(pScreen)
  617.     ScreenPtr pScreen;
  618. {
  619.     xfree(pScreen->WindowPrivateSizes);
  620.     xfree(pScreen->GCPrivateSizes);
  621.     xfree(pScreen->devPrivates);
  622.     xfree(pScreen);
  623. }
  624.